package com.tekj.cxqcb.view.Module.activity;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.amap.api.services.core.LatLonPoint;
import com.tekj.cxqcb.MainBActivity;
import com.tekj.cxqcb.R;
import com.tekj.cxqcb.config.enums.EventBusMsgBean;
import com.tekj.cxqcb.operation.BusinessDao;
import com.tekj.cxqcb.operation.resultBean.QueryCarDealerDetailsPrivateBean;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import common.base.activity.BaseActivity;
import common.base.operationHelper.Bean.BindingViewBean;
import common.conf.Service.helper.CityNameSet;
import common.tool.Tools;
import es.dmoral.toasty.Toasty;

/**
 * 共有门店
 */
public class PublicStoresDetailsActivity extends BaseActivity {


    BusinessDao businessDao;
    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.tv_l)
    TextView tvL;
    @BindView(R.id.ll_back)
    LinearLayout llBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_r)
    ImageView ivR;
    @BindView(R.id.tv_r)
    TextView tvR;
    @BindView(R.id.ll_right)
    LinearLayout llRight;
    @BindView(R.id.rl_title_bg)
    RelativeLayout rlTitleBg;
    @BindView(R.id.img_photo)
    ImageView imgPhoto;
    @BindView(R.id.tv_title_name)
    TextView tvTitleName;
    @BindView(R.id.tv_num)
    TextView tvNum;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.ll_Shop)
    LinearLayout llShop;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_szdq)
    TextView tvSzdq;
    @BindView(R.id.tv_address2)
    TextView tvAddress2;
    @BindView(R.id.tv_syz)
    TextView tvSyz;
    @BindView(R.id.tv_phone)
    TextView tvPhone;

    @Override
    public void init() {
        tvTitle.setText("车行管理");
        businessDao = new BusinessDao(activity, activity);

        businessDao.QueryCarDealerDetailsPublic(MainBActivity.User.getUserId(),
                MainBActivity.latLonPoin.getLongitude(),
                MainBActivity.latLonPoin.getLatitude());
    }

    @Override
    public int setLayout() {
        return R.layout.activity_public_stores_details;
    }

    @Override
    public void initLoadStart() {
        loading.show();
    }

    @Override
    public void initLoadEnd() {
        loading.dismiss();
    }

    @Override
    public void initBindingView(Object mBean) {
        BindingViewBean bindingViewBean = (BindingViewBean) mBean;
        switch (bindingViewBean.getmEnumStatus()) {
            case 公有车行:
                QueryCarDealerDetailsPrivateBean typeBean = (QueryCarDealerDetailsPrivateBean) bindingViewBean.getBean();
                if (typeBean.getCode().equals("0000000")) {
                    try {
                        setData(typeBean.getData());
                    }catch (NullPointerException e){
                        Toasty.normal(activity,"门店信息获取失败").show();
                        finish();
                    }

                }
                break;
        }
    }


    @OnClick(R.id.ll_back)
    public void onViewClicked() {
        finish();
    }

    void setData(QueryCarDealerDetailsPrivateBean.DataBean bean) {
        Tools.picassoNetwork(bean.getStorefrontPicture(), imgPhoto);
        tvTitleName.setText(bean.getCarDealerName());
        tvAddress.setText(bean.getRegion() + bean.getDetailedAddress());

        tvNum.setText(bean.getDistance()+"km");
        tvName.setText(bean.getCarDealerName());
        tvSzdq.setText(bean.getRegion());
        tvAddress2.setText(bean.getDetailedAddress());
        tvSyz.setText(bean.getCarDealerHost());
        tvPhone.setText(bean.getPhone());
    }
}
